package com.example.common;

import lombok.Data;

@Data
public class Result {

    private int code;//编码 200/400
    private String msg;//成功/失败
    private Long total;//总记录数
    private Object data;//数据
    private String Code;

    public Result setCode(String code) {
        Code = code;
        return this;
    }

    public int getCode() {
        return code;
    }

    public Result setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Long getTotal() {
        return total;
    }

    public Result setTotal(Long total) {
        this.total = total;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }
    public static Result fail2(String messaeg){
        return result(400,messaeg,0L,null,null);
    }
    public static Result fail(){
        return result(400,"失败",0L,null,null);
    }

    public static Result suc(){
        return result(200,"成功",0L,null,null);
    }

    public static Result suc(Object data){
        return result(200,"成功",0L,data,null);
    }

    public static Result suc(Object data,Long total){
        return result(200,"成功",total,data,null);
    }
    public static Result suc(String Code,Object data){
        return result(200,"成功",null,data,Code);
    }
    private static Result result(int code,String msg,Long total,Object data,String Code){
        Result res = new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        return res;
    }
}
